<?php
namespace app\index\controller;
use think\Db;
use lib\cs;

class Index
{
    protected $middleware = ['Check'];
    public function index(){
        if(gc('typeLogin')==null){
            return redirect('login/index');
        }
        $data['data']= gc('userData');
        return view("index",$data);

        //return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }
    public  function  selectTypeLogin(){//查询登录状态
        if(gc('typeLogin')==null){
            return 0;
        }else{
            return gc('typeLogin');
        }
    }

    public  function  welcome(){
        return 'welcome';
        //return view("welcome");
    }

    public  function  articleList(){//数据管理页面
        $data['data']=array(gc('typeLogin'),gc('userData'));
        return view("articleList",$data);
    }

    public function  dataSelect(){//搜索查询
        $id=input('id');$min=input('min');$max=input('max');$phone=input('phone');
        $name=gc('userData')['name'];
        $department=gc('userData')['department'];

        if(gc('typeLogin')==2)$id=intval($name);//非管理员获取
        if(gc('typeLogin')==1){//管理员权限
            $selectStr='';
            if($phone){
                //$selectStr.="FRemoteNum='{$phone}'";
                $selectStr.="FRemoteNum like '%{$phone}%'";
                if($id)$selectStr.="and  FLocalNum={$id}";
                if($min)$selectStr.="and FDTStart>='{$min}'";
                if($max)$selectStr.="and FDTStart<='{$max} 23:59:59'";
            }
        }


        $arr=array();
        if(!empty($phone)&&$phone!='undefined'){
            $arr=Db::query("select top 500  FLocalNum,FDTStart,FRemoteNum,FLong,FIO,FFile from raCall where {$selectStr} order by FDTStart desc");
            $arr=$this->children_handleSarr($arr);
        }else if(empty($id)||empty($min)||empty($max)){
        }else{
            $arr=Db::query("select top 500  FLocalNum,FDTStart,FRemoteNum,FLong,FIO,FFile from raCall where FLocalNum='{$id}' and FDTStart>='{$min}' and FDTStart<='{$max} 23:59:59' order by FDTStart desc");
            $arr=$this->children_handleSarr($arr);
        }

        //....
        $data['data']=array(gc('typeLogin'),gc('userData'));
        $data['arr']=$arr;
        $data['min']=$min;$data['max']=$max;$data['id']=$id;$data['phone']=$phone;

        if(gc('typeLogin')==1&&$name!='admin'){
            $FLocalArr=judgeFLocalNum($name,$id,$arr,$department);//权限 查询分机范围
            $data['arr']=$FLocalArr;
        }

        return view("articleList",$data);
        //....
    }
    public function children_handleSarr($arr){
        foreach($arr as $key=>$values){
            if($values['FIO']<1){
                $arr[$key]['FIO']='接入';
            }else{
                $arr[$key]['FIO']='播出';
            }

            //$values['FFile']=str_replace('D:\\TMNData\\','/www/wwwroot/tp5/public/static/TMNData2/',$values['FFile']);
            //$arr[$key]['FFile']=str_replace("\\",'/',$values['FFile']);

            $arr[$key]['FFile']=str_replace("\\",'\\\\',$values['FFile']);
        }
        return $arr;
    }
}
